/**
 * Created by 123456 on 2017/1/12.
 */
/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',"business/videoIndex/services/httpServices","jquery","slide","business/videoIndex/directive/lunbo","business/videoIndex/directive/scroll"],function(require,app,httpServices,constant){
    app.controller('videoIndexCtrl',function($scope,$http,$stateParams,$state){
        $scope.isDetailPage = true;
        $scope.isMainpage = false;

   		$scope.linkvieoList=function(){
   			sessionStorage.topId=$scope.worPlanId
   			$state.go("eng.vedio")
   		}
   		$scope.linkCollage=function(){
   			sessionStorage.topId=$scope.workCollegeId
   			$state.go("eng.vedio")
   		}
   		$scope.linkProject=function(){
   			sessionStorage.topId=$scope.projectId
   			$state.go("eng.vedio")
   		}
   		$scope.LinkDesignName=function(){
   			sessionStorage.topId=$scope.workDesignId
   			$state.go("eng.vedio")
   		}
   		$scope.linkCOnDesign=function(){
   			sessionStorage.topId=$scope.COnDesignId
   			$state.go("eng.vedio")
   		}
   		$scope.LinkCostCollageName=function(){
   			sessionStorage.topId=$scope.CostCollageId
   			$state.go("eng.vedio")
   		}
   		$scope.linkDaren=function(){
   			sessionStorage.topId=$scope.DarenId
   			$state.go("eng.vedio")
   		}
   		$scope.goCOursDe=function(item){
			$state.go("eng.vedioDetails",{courseId:item.courseId})
		}
        $scope.heaerLinkCOlor=function(item,index){
            $scope.fontc=index;
            var scrollTop = $(document).scrollTop();
            if(item.tcName == $scope.worPlan){
            	scrollTop=$("#worPlan").offset().top-50+"px";
            /*	$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.workCollege){
            	scrollTop=$("#workCollege").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.projectName){
            	scrollTop=$("#projectName").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.workDesignName){
            	scrollTop=$("#workDesignName").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.COnDesign){
            	scrollTop=$("#COnDesign").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.CostCollageName){
            	scrollTop=$("#CostCollageName").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }else if(item.tcName == $scope.DarenClass){
            	scrollTop=$("#DarenClass").offset().top-50;
            	/*$(document).scrollTop(scrollTop)*/
            	$('html,body').animate({scrollTop: scrollTop}, 200)
            }
        }
       

        //点击移动
        var page = 1;
        $scope.i = 4; //每版放4个图片

        //向后 按钮
        $scope.control=0;
        $scope.showControl=function(){
            $scope.control=1;
        }
        $scope.hideontrol=function(){
            $scope.control=0;
        }
        $scope.smallMove = function() {
            $scope.i = 4; //每版放4个图片
                //往前 按钮
            pre("smabanner","headerUlTwo")
        }
        $scope.smallMove2=function(){
            $scope.i = 4; //每版放4个图片
            //往后 按钮
            next("smabanner","headerUlTwo")
        }
        /*执业*/
     
        $scope.fons3=$scope.bgs6=$scope.bgs5=$scope.bgs4=$scope.bgs3=$scope.bgs2=$scope.bgs=0;
        $scope.clearOne=function(){
            $scope.fons=-1;
        }
        $scope.clearTwo=function(){
            $scope.fons2=-1;
        }
        $scope.clearTHr=function(){
            $scope.fons3=-1;
            var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.DarenId,
					pageNo:1,
					pageSize:4
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.DarenCourseList = response.data.list;
                   
                })
            });
            
            
        }
        $scope.saveOneClass=function(item,index){
        	$scope.fons=-1;
            $scope.bgs=index;
            $scope.workId= item.scId
             var req ={
                type:"GET",
                uri:"getThirdCategory",
                data:{
                    scId:item.scId
                }
            };
            httpServices.getcourseCata(req).success(function(response){
                $scope.$apply(function(){
                    $scope.proa2 = response.data;
                })
            });
            
            var req ={
                type:"GET",
                uri:"getList",
                data:{
                    tcId:$scope.worPlanId,
                    scId:item.scId                   
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.courseListCons = response.data.list;
                   
                })
            });
		                      
        }
        $scope.saveH=function(item,index){
            $scope.fons=index;
            var id=$scope.workId;
            if($scope.workId!=undefined){
            	var req ={
                type:"GET",
                uri:"getList",
                data:{
                	tcId:$scope.worPlanId,
                    scId:id,
                    thirdId:item.dcId   
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.courseListCons = response.data.list;
                   
                })
            });
            }else{
            	var req ={
                type:"GET",
                uri:"getList",
                data:{
                    thirdId:item.dcId   
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.courseListCons = response.data.list;
                })
            });
            }
             
        }
        $scope.smallMoves=function(){
            $scope.i = 9;
            pre("PrathRclass","OulTos")
        }
        $scope.smallMoves2=function(){
            $scope.i= 9;
            next("PrathRclass","OulTos")
        }

        $scope.saveOneClass2=function(item,index){
        	$scope.fons2=-1;
            $scope.bgs2=index;
            $scope.worcollagekId= item.scId
             var req ={
                type:"GET",
                uri:"getThirdCategory",
                data:{
                    scId:item.scId
                }
            };
            httpServices.getcourseCata(req).success(function(response){
                $scope.$apply(function(){
                    $scope.collageStu = response.data;
                })
            });
            
            var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.workCollegeId,
                    scId:item.scId,
					pageNo:1,
					pageSize:4
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.collageCourseList = response.data.list;
                   
                })
            });
            
            
        }
        $scope.saveTc=function(item,index){
            $scope.fons2=index;
            if($scope.worcollagekId!=undefined){
            	var req ={
                type:"GET",
                uri:"getList",
                data:{
                    tcId:$scope.workCollegeId,
                    scId:$scope.worcollagekId,
                    thirdId:item.dcId,
                    pageNo:1,
					pageSize:4
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.collageCourseList = response.data.list;
                   
                })
            });
            }else{
            	var req ={
                type:"GET",
                uri:"getList",
                data:{
                    tcId:$scope.workCollegeId,
                    thirdId:item.dcId
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.collageCourseList = response.data.list;
                   
                })
                  });
            }
            
            
        }
        $scope.smallMovecollage=function(){
            $scope.i = 9;
            pre("PrathRclass2","OulTos2")
        }
        $scope.smallMovcoll=function(){
            $scope.i= 9;
            next("PrathRclass2","OulTos2")
        }
        $scope.switcDataPro=function(item,index){
            $scope.bgs3=index;
            
            var req ={
                type:"GET",
                uri:"getList",
                data:{ 
                    tcId:$scope.projectId,
                    scId:item.scId,
                    pageNo:1,
                    pageSize:3
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.projectCourseList = response.data.list;
                   
                })
                  });
           
            
            
            
        }
        $scope.switcDataeng=function(item,index){
            $scope.bgs4=index;
            
             var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.workDesignId,
                    scId:item.scId,
					pageNo:1,
					pageSize:3
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.DesignCourseList = response.data.list;
                   
                })
            });
            
        }
        $scope.switcDataCon=function(item,index){
            $scope.bgs5=index;
            
            
             var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.COnDesignId,
                    scId:item.scId,
					pageNo:1,
					pageSize:3
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.conDesignCourseList = response.data.list;
                   
                })
            });
				     
            
        }
        $scope.switcDatacst=function(item,index){
            $scope.bgs6=index;
             var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.CostCollageId,
                    scId:item.scId,
					pageNo:1,
					pageSize:3
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.CostCollageCourseList = response.data.list;
                   
                })
            });
	     
				     
        }
        $scope.smallMovepeople=function(){
            $scope.i = 9;
            pre("PrathRclass3","OulTos3")
        }
        $scope.smallMovpeo=function(){
            $scope.i = 9;
            next("PrathRclass3","OulTos3")
        }
        $scope.savepeop=function(item,index){
            $scope.fons3=index;
             var req ={
                type:"GET",
                uri:"getList",
                data:{
                   
                    tcId:$scope.DarenId,
                    scId:item.scId,
					pageNo:1,
					pageSize:4
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.DarenCourseList = response.data.list;
                   
                })
            });
				     
        }
        $scope.clearCouse=function(){
        	$scope.bgs3=-1;
        	
        	 var req ={
                type:"GET",
                uri:"getList",
                data:{ 
                    tcId:$scope.projectId,
					pageNo:1,
					pageSize:3
                    
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.projectCourseList = response.data.list;
                   
                })
            });
        	
        	
        }
        function next(content,list){
            var content = $("div#"+content);
            var content_list = $("ul#"+list);
            var v_width = content.width();
            var len = content.find("li").length;
            var page_count = Math.ceil(len / $scope.i);   //只要不是整数，就往大的方向取最小的整数
            if (!content_list.is("d")) {    //判断“内容展示区域”是否正在处于动画
                if (page == page_count) {  //已经到最后一个版面了,如果再向后，必须跳转到第一个版面。
                    content_list.animate({left: '0px'}, "slow"); //通过改变left值，跳转到第一个版面
                    page = 1;
                } else {
                    content_list.animate({left: '-=' + v_width}, "slow");  //通过改变left值，达到每次换一个版面
                    page++;
                }
            }
        }
        function pre(content,list){
            var content = $("div#"+content);
            var content_list = $("ul#"+list);
            var v_width = content.width();
            var len = content.find("li").length;
            var page_count = Math.ceil(len / $scope.i);   //只要不是整数，就往大的方向取最小的整数
            if (!content_list.is("d")) {    //判断“内容展示区域”是否正在处于动画
                if (page == 1) {  //已经到第一个版面了,如果再向前，必须跳转到最后一个版面。
                    content_list.animate({left: '-=' + v_width * (page_count - 1)}, "slow");
                    page = page_count;
                } else {
                    content_list.animate({left: '+=' + v_width}, "slow");
                    page--;
                }
            }
        }
        
/*请求*/
/*热门推荐1课程*/
function gethotCour(){
	  var req ={
                type:"GET",
                uri:"getHotCourse",
                data:{
	                  all:true,
	                  pageNo:1,
					 pageSize:4
                }
            };
            httpServices.getSameVideo2(req).success(function(response){
                $scope.$apply(function(){
                    $scope.courseList = response.data.list;
                })
	   });
}
gethotCour();

/*一级分类*/
	function oneClass(){//一级分类
            var req ={
                type:"GET",
                uri:"getTopCategory",
                data:{
                  
                }
            };
            httpServices.getcourseCata(req).success(function(response){
                $scope.$apply(function(){
                    $scope.oneClassTit=response.data;
                    $scope.worPlan=response.data[0].tcName;
                    $scope.worPlanId=response.data[0].tcId;
                    $scope.worTotal=response.data[0].totalCount;
                    $scope.workCollege=response.data[1].tcName;
                    $scope.workCollegeId=response.data[1].tcId;
                    $scope.workCollegeTotal=response.data[1].totalCount;
                    $scope.projectName=response.data[2].tcName;
                    $scope.projectId=response.data[2].tcId;
                    $scope.projectTotal=response.data[2].totalCount;
                    $scope.workDesignName=response.data[3].tcName;
                    $scope.workDesignId=response.data[3].tcId;
                    $scope.workDesignTotal=response.data[3].totalCount;
                    $scope.COnDesign=response.data[4].tcName;
                    $scope.COnDesignId=response.data[4].tcId;
                    $scope.COnDesignTotal=response.data[4].totalCount;
                    $scope.CostCollageName=response.data[5].tcName;
                    $scope.CostCollageId=response.data[5].tcId;
                    $scope.CostCollageTotal=response.data[5].totalCount;
                    $scope.DarenClass=response.data[6].tcName;
                    $scope.DarenId=response.data[6].tcId;
                    $scope.DarenTotal=response.data[6].totalCount;
                    DaRRen(response.data[6].tcId);//达人课堂
                    CostCollage(response.data[5].tcId);//成本管理
                    COnDesign(response.data[4].tcId);//施工技术
                    workDesigntwoClass(response.data[3].tcId)//工业设计
                    workPlantwoClass(response.data[0].tcId);//z执业
                    workCollegetwoClass(response.data[1].tcId);//云大学课程
                    projecttwoClass(response.data[2].tcId)//项目管理
                })
	   });
	}
oneClass();

		function DaRRen(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id,
		        	pageNo:1,
		        	pageSize:7
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.DarenCLass = response.data.list;
		            var towId = response.data.list[0].scId
				     
				      var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:response.data.list[0].scId,
								pageNo:1,
								pageSize:3
                                
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.DarenCourseList = response.data.list;
                               
                            })
                        });
				     
				     
				        })
				    });
				
		}


		function CostCollage(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id,
		        	pageNo:1,
		        	pageSize:7
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.CostCollageCLass = response.data.list;
		            var towId = response.data.list[0].scId
				     
				      var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:response.data.list[0].scId,
								pageNo:1,
								pageSize:3
                                
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.CostCollageCourseList = response.data.list;
                               
                            })
                        });
				     
				     
				        })
				    });
				
		}

		function COnDesign(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id,
		        	pageNo:1,
		        	pageSize:7
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.ConDesignClass = response.data.list;
		            var towId = response.data.list[0].scId
				     
				      var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:response.data.list[0].scId,
								pageNo:1,
								pageSize:3
                                
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.conDesignCourseList = response.data.list;
                               
                            })
                        });
				     
				     
				        })
				    });
				
		}

		function workDesigntwoClass(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id,
		        	pageNo:1,
		        	pageSize:7
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.DesignClass = response.data.list;
		            var towId = response.data.list[0].scId
				     
				      var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:response.data.list[0].scId,
								pageNo:1,
								pageSize:3
                                
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.DesignCourseList = response.data.list;
                               
                            })
                        });
				     
				     
				        })
				    });
				
		}

		function projecttwoClass(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id,
		        	pageNo:1,
		        	pageSize:7
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.projectClass = response.data.list;
		            var towId = response.data.list[0].scId
				     
				      var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:response.data.list[0].scId,
								pageNo:1,
								pageSize:3
                                
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.projectCourseList = response.data.list;
                               
                            })
                        });
				     
				     
				        })
				    });
				
		}

		function workCollegetwoClass(id){
				var req ={
			        type:"GET",
			        uri:"getSecondaryCategory",
			        data:{
			        	tcId:id
			        }
			    };
			    httpServices.getcourseCata(req).success(function(response){
			        $scope.$apply(function(){
			            $scope.collageClass = response.data.list;
			            var towId = response.data.list[0].scId
					     var req ={
			                type:"GET",
			                uri:"getThirdCategory",
			                data:{
			                    scId:response.data.list[0].scId
			                }
			            };
			            httpServices.getcourseCata(req).success(function(response){
			                $scope.$apply(function(){
			                    $scope.collageStu = response.data;
			                    
			                var req ={
	                            type:"GET",
	                            uri:"getList",
	                            data:{
	                               
	                                tcId:id,
	                                scId:towId
	
	                                
	                            }
	                        };
	                        httpServices.getcourse(req).success(function(response){
	                            $scope.$apply(function(){
	                                $scope.collageCourseList = response.data.list;
	                               
	                            })
	                        });
			                    
			                    
			                })
			            });
					        })
					    });
					
			}
	
		function workPlantwoClass(id){
			var req ={
		        type:"GET",
		        uri:"getSecondaryCategory",
		        data:{
		        	tcId:id
		        }
		    };
		    httpServices.getcourseCata(req).success(function(response){
		        $scope.$apply(function(){
		            $scope.proa = response.data.list;
		            var towId = response.data.list[0].scId
				     var req ={
		                type:"GET",
		                uri:"getThirdCategory",
		                data:{
		                    scId:response.data.list[0].scId
		                }
		            };
		            httpServices.getcourseCata(req).success(function(response){
		                $scope.$apply(function(){
		                    $scope.proa2 = response.data;
		                    
		                var req ={
                            type:"GET",
                            uri:"getList",
                            data:{
                               
                                tcId:id,
                                scId:towId   
                            }
                        };
                        httpServices.getcourse(req).success(function(response){
                            $scope.$apply(function(){
                                $scope.courseListCons = response.data.list;
                               
                            })
                        });
		                    
		                    
		                })
		            });
				        })
				    });
				
		}

    })
})

